"""
笔记模型
用于演示 CRUD 基类和数据权限隔离
"""
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime

class NoteBase(BaseModel):
    """笔记基础信息"""
    title: str = Field(..., min_length=1, max_length=200, description="笔记标题")
    content: str = Field(..., min_length=1, description="笔记内容")

class NoteCreate(NoteBase):
    """创建笔记"""
    pass

class NoteUpdate(BaseModel):
    """更新笔记（所有字段可选）"""
    title: Optional[str] = Field(None, min_length=1, max_length=200)
    content: Optional[str] = Field(None, min_length=1)

class NoteInDB(NoteBase):
    """数据库中的笔记"""
    user_id: str
    created_at: datetime
    updated_at: Optional[datetime] = None

class NoteOut(NoteBase):
    """返回给客户端的笔记"""
    id: str
    user_id: str
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True

